<script type="text/javascript">
$(document).ready(function() {
    var initial_width;
    //初始化完成
    $('#rrclient_table').jqGrid({
        url: '/grid_rrclient',
        styleUI: 'Bootstrap',
        datatype: 'json',
        mtype: 'POST',
        colNames: ['编号', "[['label name'|translate ]]", '源卷', '目标卷', '站点', '间隔', '带宽',
            "[['label owner'|translate]]",
            '[["label Creation time"|translate]]', '[["label operation"|translate]]'
        ],
        colModel: [{
            name: 'id',
            index: 'id',
            width: 6,
            align: '',
            hidden: true
        }, {
            name: 'name',
            index: 'name',
            width: 6,
            align: 'left',
            formatter:function(cell,option,row) {
                return '<a href="#" onclick="detail_open(\'' + option.gid + '\',\'' + option.rowId + '\')">' + cell + '</a>';
            },
            unformat: function(cell) {
                return cell;
            }
        }, {
            name: 'src_volume_path',
            index: 'src_volume_path',
            width: 8,
            align: 'left',
            formatter: function(cellvalue, option, row) {
            var outerWidth = $('#rrclient_table_src_volume_path').width() - 20;
            return '<span style="display:inline-block;text-overflow:ellipsis; white-space:nowrap;overflow:hidden;width:' + outerWidth + 'px;" href="#">' + cellvalue + '</span>';
        },
        unformat: function(cellvalue) {
            return cellvalue;
        }
        }, {
            name: 'dst_volume_path',
            index: 'dst_volume_path',
            width: 8,
            align: 'left',
            formatter: function(cellvalue, option, row) {
            var outerWidth = $('#rrclient_table_src_volume_path').width() - 20;
            return '<span style="display:inline-block;text-overflow:ellipsis; white-space:nowrap;overflow:hidden;width:' + outerWidth + 'px;" href="#">' + cellvalue + '</span>';
        },
        unformat: function(cellvalue) {
            return cellvalue;
        }
        }, {
            name: 'sites',
            index: 'sites',
            width: 8,
            align: 'left',
            sortable: false
        }, {
            name: 'interval',
            index: 'interval',
            width: 8,
            align: 'left',
            formatter:function(cell,option,row) {
                return '<span>' + cell + "秒" + '</span>';
            },
            unformat: function(cell) {
                return cell;
            }
        }, {
            name: 'qos',
            index: 'qos',
            width: 8,
            align: 'left'
        }, {
            name: 'username',
            index: 'username',
            width: 6,
            align: 'left'
        }, {
            name: 'created_at',
            index: 'created_at',
            width: 12,
            align: 'left'
        }, {
            name: 'service',
            index: 'service',
            width: 20,
            align: 'left',
            sortable: false,
            detailHidden: true,
            formatter: function(cell,option,row) {
                row = row2object(row,option.gid);
                var html = '';
                html += '<button title="编辑" class="btn btn-blue" onclick=confirm_rrclient_update(' + row['id'] + ')>编辑</button>';
                html += '<button style="margin-left:10px;" title="删除" class="btn btn-blue" onclick=confirm_rrclient_delete(' + row['id'] + ')>删除</button>';
                return html;
            }
        }],
        page: 1,
        rowNum: 10,
        sortname: 'id',
        sortorder: 'desc',
        viewrecords: true,
        //caption: '磁盘列表',
        altclass: 'ui-priority-secondary',
        altRows: true,
        autowidth: true,
        height: mainpanelHeight,
        shrinkToFit: true,
        beforeSelectRow:function(rowid, e) {
            if($(e.target).is('input')) {
                return true;
            }
            return false;
        },
        gridComplete: function() {

            var gridData = $(this).jqGrid('getRowData');
            jqgrid_page($(this), gridData);
            jqgrid_resize($(this));
            
        },
        resizeStart: function() {
            initial_width = $(this).width();
        },
        resizeStop: function() {
            return
        }
    });
});

function rrclient_delete(rrclient_id) {
    $.post("/rrclient_delete", {
            'id': rrclient_id
        },
        function(data) {
            if (data.reply.is_success) {
                $('#rrclient_table').trigger("reloadGrid");
                //                    SelfAlert("删除成功", "完成提示");
            } else {
                error = data.reply.error;
                SelfAlert("删除失败：" + error)
            }
        });
}

function confirm_rrclient_update(rrclient_id) {
    angular.element('#rrclient_controller').scope().open("/rrclient_update?id=" + rrclient_id);
}

function confirm_rrclient_delete(rrclient_id) {
    msg = '确认删除?';
    SelfConfirm(msg, rrclient_delete, rrclient_id, "删除提示");
}
$("#rrclient_create").click(function() {
    angular.element('#rrclient_controller').scope().open("/rrclient_create");
});
</script>
<div class="panel panel-f-style">
    <div class="panel-body">
        <div class="title-tag">
            <h3>复制关系</h3>
            <p>复制关系管理</p>
        </div>
        <div class="grid-tools">
            <!-- <div class="grid-search-down-arrow">
                <i class="fa fa-angle-down"></i>
            </div> -->
            <div class="grid-operate pull-left">
                <button id="rrclient_controller" ng-controller="RRClientModalCtrl" ng-hide="true"></button>
                <button class="btn btn-blue" id="rrclient_create" type="button">[['button create'|translate]]</button>
            </div>
        </div>
        <div class="grid-body" id="div_rrclient_table">
            <table id="rrclient_table"></table>
        </div>
    </div>
</div>
